<?php

use Workerman\Worker;
use Workerman\Timer;
use PHPSocketIO\SocketIO;
require_once '../vendor/autoload.php';

// Listen port 2021 for socket.io client
$io = new SocketIO(2099);
$io->on('connection', function ($socket) use ($io) {
    $socket->on('chat message', function ($msg) use ($io) {
        $io->emit('chat message', $msg);
    });
});

$io->on('workerStart', function() use ($io) {
    // 每2.5秒执行一次
    $time_interval = 2.5;
    Timer::add($time_interval, function()
    {
        echo "task run\n";
    });
});

Worker::runAll();